
/* 
@title: Sprigressbar
@description: Sprigressbar is a game where you try to fill a progress bar by collecting blue or orange segments while dodging red ones and small sprigs.
@author: MathR
@tags: []
@addedOn: 2023-08-21
*/

    // Based on the game Progressbar95
// Fill your bar with segments to move to the next level
// At the end of each level you gain 5 points for each blue segment
// Avoid red segments at all cost!
// Move your bar using wasd
// Move your cursor using ijkl to close the annoying mascots

const music = tune`
182.9268292682927: D5-182.9268292682927 + C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: B4^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: E5~182.9268292682927 + D5^182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927 + C5^182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927 + C5^182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + D5^182.9268292682927,
182.9268292682927: B4~182.9268292682927 + E5^182.9268292682927,
182.9268292682927: B4~182.9268292682927 + D5^182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C5^182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: D5-182.9268292682927 + C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927 + E5^182.9268292682927,
182.9268292682927: A4~182.9268292682927 + D5^182.9268292682927,
182.9268292682927: A4~182.9268292682927 + C5^182.9268292682927,
182.9268292682927: A4~182.9268292682927 + B4^182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: E5~182.9268292682927 + D5^182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927 + C5^182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927 + C5^182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + D5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927 + E5^182.9268292682927,
182.9268292682927: B4~182.9268292682927 + D5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C5^182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5^182.9268292682927 + A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: D5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + E5~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + E5~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5^182.9268292682927 + B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: D5^182.9268292682927 + B4~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5^182.9268292682927 + A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: D5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + E5~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + E5~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5^182.9268292682927 + B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: D5^182.9268292682927 + B4~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5^182.9268292682927 + A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: D5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + E5~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + E5~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5^182.9268292682927 + B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: D5^182.9268292682927 + B4~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: C5^182.9268292682927 + A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: D5^182.9268292682927 + A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: A4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: A4~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + E5~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + E5~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5^182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5^182.9268292682927 + B4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + B4~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: G4^182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: A4^182.9268292682927 + G4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + G4~182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + G4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + G4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: D5^182.9268292682927 + G4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + G4~182.9268292682927,
182.9268292682927: G4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: G4^182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: A4^182.9268292682927 + G4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + G4~182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: G5^182.9268292682927 + G4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + G4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: D5^182.9268292682927 + G4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + G4~182.9268292682927,
182.9268292682927: G4~182.9268292682927,
182.9268292682927: G4^182.9268292682927 + E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: A4^182.9268292682927 + E5~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: D5^182.9268292682927 + E5~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: D5^182.9268292682927 + E5~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + E5~182.9268292682927,
182.9268292682927: E5~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + E5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + D5^182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: C5^182.9268292682927 + B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + E5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927,
182.9268292682927: B4~182.9268292682927 + D5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C5^182.9268292682927 + C4-182.9268292682927,
182.9268292682927: B4~182.9268292682927 + C4-182.9268292682927`

const lbar = 'a'
const rbar = 'b'
const bar = 'c'
const be = 'd'
const eb = 'e'
const oe = 'f'
const eo = 'g'
const bbe = 'h'
const beb = 'i'
const boe = 'j'
const beo = 'k'
const re = 'l'
const er = 'm'
const blue = 'n'
const green = 'o'
const gray = 'p'
const thing = 'q'
const cursor = 'r'
const sprig_a = 's'
const sprig_b = 't'
const sprig_c = 'u'
const sprig_d = 'v'
const esprig_a = 'w'
const esprig_b = 'x'
const esprig_c = 'y'
const esprig_d = 'z'
const bsprig_a = 'A'
const bsprig_b = 'B'
const bsprig_c = 'C'
const bsprig_d = 'D'
const sky = 'E'
const cloud = 'F'
const black = 'G'
const yellow = 'H'
const bgsprig_a = 'I'
const bgsprig_b = 'J'
const bgsprig_c = 'K'
const bgsprig_d = 'L'
const cbgsprig_a = 'M'
const cbgsprig_b = 'N'
const cbgsprig_c = 'O'
const cbgsprig_d = 'P'
const pe = 'Q'
const ep = 'R'
const ge = 'S'
const eg = 'T'
const heart = 'U'

const error_snd = tune`
94.9367088607595: C4/94.9367088607595,
94.9367088607595: C4/94.9367088607595,
94.9367088607595: C4/94.9367088607595,
94.9367088607595: C4/94.9367088607595,
94.9367088607595: C4/94.9367088607595,
94.9367088607595: C4/94.9367088607595,
94.9367088607595: C4/94.9367088607595,
94.9367088607595: C4/94.9367088607595,
2278.481012658228`
const levelup_snd = tune`
214.28571428571428: B4-214.28571428571428 + A4/214.28571428571428,
214.28571428571428,
214.28571428571428: B4-214.28571428571428 + A4/214.28571428571428,
214.28571428571428: B4-214.28571428571428 + A4/214.28571428571428,
214.28571428571428: B4-214.28571428571428 + A4/214.28571428571428,
214.28571428571428,
214.28571428571428: B4-214.28571428571428 + A4/214.28571428571428,
214.28571428571428,
214.28571428571428: B4-214.28571428571428 + A4/214.28571428571428,
4928.571428571428`
const break_snd = tune`
500: D4^500,
15500`
const get_snd = tune`
500: C5~500,
15500`
const touch_snd = tune`
167.5977653631285: C4/167.5977653631285,
5195.530726256983`
const bonus_snd = tune`
148.5148514851485: C4~148.5148514851485,
148.5148514851485: G4~148.5148514851485,
4455.445544554455`

setLegend(
  [cursor, bitmap`
................
....0...........
....00..........
....020.........
....0220........
....02220.......
....022220......
....0222220.....
....02222220....
....022222220...
....0222200000..
....022020......
....020.020.....
....00..020.....
....0....0......
................`],
  [sprig_a, bitmap`
..........00000.
.........0444440
........04444044
.......044440444
......0444004444
......0440444440
......040444400.
......0044000...
......0440......
......000...0000
..........002222
........00222222
........02222222
.......022222222
.......022222222
......0000022222`],
  [sprig_b, bitmap`
................
00..............
00000...........
00.000..........
0..00...........
..00............
..00............
..00............
.000............
000000..........
22222200........
222222220.......
2222222220......
2222222220......
22222222220.....
00000222220.....`],
  [sprig_c, bitmap`
00002022220.....
00002022220.....
02220022220.....
20002222220.....
22222222220.....
22222222220.....
22222200220.....
22000022220.....
00222222220.....
22222222220.....
22222222220.....
22222222220.....
22222222220.....
22222222220.....
2222222220......
2222222220......`],
  [sprig_d, bitmap`
......0000202220
......0200202220
......0000022220
.....02222222222
.....02222222222
.....02222222222
.....02222222222
......0222222222
.......000222222
..........000000
..............02
..............02
.............022
.............022
............0022
............0222`],
  [bsprig_a, bitmap`
..........00000.
.........0333330
........03333033
.......033330333
.....60333003333
....6.0330333330
....6.030333300.
.....66666666666
......0330......
......000...0000
..........002222
........00222222
........02222222
.......022222222
.......022222222
......0000022222`],
  [bsprig_b, bitmap`
................
00..............
00000...........
00.000..........
0660066.........
..00...6........
..00...6........
6666666.........
.000............
000000..........
22222200........
222222220.......
2222222220......
2222222220......
22222222220.....
00000222220.....`],
  [bsprig_c, bitmap`
00002022220.....
00002020220.....
02220020020.....
20002220220.....
22222220220.....
22222200220.....
22222002220.....
22000022220.....
00222222220.....
22222222220.....
22222222220.....
22222222220.....
22222222220.....
22222222220.....
22222222220.....
2222222220......`],
  [bsprig_d, bitmap`
......0000202220
......0200202220
......0000022220
.....02222222222
.....02222222222
.....02222222222
.....02222222222
......0222222222
.......000222222
..........000000
..............02
..............02
.............022
.............022
.............022
............0222`],
  [esprig_a, bitmap`
..........3.....
....3.333.33....
.....3333333..0.
..3..33363330000
....333666330000
.....3366633...0
.....3336333....
.....333333.....
......333.......
............0000
..........002222
........00222222
........020.2222
.......022200222
.......022222022
......0000022222`],
  [esprig_b, bitmap`
................
00..............
00000...........
00.000..........
0..00...........
..00............
..00............
..00............
.000............
000000..........
22222200........
222202220.......
2200222220......
20.2222220......
22222222220.....
00000222220.....`],
  [esprig_c, bitmap`
00002022220.....
00002022220.....
02220022220.....
20002222220.....
22222222220.....
22222222220.....
22222200220.....
22000022220.....
00222222220.....
22222222220.....
22222222220.....
22222222220.....
22222222220.....
22222222220.....
2222222220......
2222222220......`],
  [esprig_d, bitmap`
......0000202220
......0200202220
......0000022220
.....02222222222
.....02222222222
.....02222222222
.....02222222222
......0222222222
.......000222222
..........000000
..............02
..............02
.............022
.............022
............0022
............0222`],
  [lbar, bitmap`
1111111111111111
1111111111111111
11..............
11..............
11..............
11..............
11..............
11..............
11..............
11..............
11..............
11..............
11..............
11..............
1111111111111111
1111111111111111`],
  [rbar, bitmap`
1111111111111111
1111111111111111
..............11
..............11
..............11
..............11
..............11
..............11
..............11
..............11
..............11
..............11
..............11
..............11
1111111111111111
1111111111111111`],
  [bar, bitmap`
1111111111111111
1111111111111111
................
................
................
................
................
................
................
................
................
................
................
................
1111111111111111
1111111111111111`],
  [be, bitmap`
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........`],
  [eb, bitmap`
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555`],
  [oe, bitmap`
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........`],
  [eo, bitmap`
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999`],
  [re, bitmap`
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........
33333333........`],
  [er, bitmap`
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333
........33333333`],
  [pe, bitmap`
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........
88888888........`],
  [ep, bitmap`
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888
........88888888`],
  [ge, bitmap`
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........
LLLLLLLL........`],
  [eg, bitmap`
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL
........LLLLLLLL`],
  [bbe, bitmap`
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........
55555555........`],
  [beb, bitmap`
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555
........55555555`],
  [boe, bitmap`
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........
99999999........`],
  [beo, bitmap`
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999
........99999999`],
  [blue, bitmap`
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555`],
  [green, bitmap`
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444`],
  [heart, bitmap`
1111111111111111
1111111111111111
1111111111111111
1111331113311111
1113333133331111
1133333333333111
1133333333333111
1133333333333111
1133333333333111
1113333333331111
1111333333311111
1111133333111111
1111113331111111
1111111311111111
1111111111111111
1111111111111111`],
  [gray, bitmap`
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111`],
  [thing, bitmap`
................
................
................
................
................
................
................
................
................
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111`],
  [sky, bitmap`
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777`],
  [cloud, bitmap`
................
................
........22......
.......22222....
......222222....
...222222222222.
.222222222222222
2222222222222222
2222222222222222
2222222222222222
222222222222222.
2222222222222...
................
................
................
................`],
  [black, bitmap`
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222
2222222222222222`],
  [yellow, bitmap`
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666`],
  [bgsprig_a, bitmap`
..........00000.
.........0LLLLL0
........0LLLL0LL
.......0LLLL0LLL
......0LLL00LLLL
......0LL0LLLLL0
......0L0LLLL00.
......00LL000...
......0LL0......
......000...0000
..........001111
........00111111
........01111111
.......011111111
.......011111111
......0000011111`],
  [bgsprig_b, bitmap`
................
00..............
00000...........
00.000..........
0..00...........
..00............
..00............
..00............
.000............
000000..........
11111100........
111111110.......
1111111110......
1111111110......
11111111110.....
00000111110.....`],
  [bgsprig_c, bitmap`
00001011110.....
00001011110.....
01110011110.....
10001111110.....
11111111110.....
11111111110.....
11111100110.....
11000011110.....
00111111110.....
11111111110.....
11111111110.....
11111111110.....
11111111110.....
11111111110.....
1111111110......
1111111110......`],
  [bgsprig_d, bitmap`
......0000101110
......0100101110
......0000011110
.....01111111111
.....01111111111
.....01111111111
.....01111111111
......0111111111
.......000111111
..........000000
..............01
..............01
.............011
.............011
............0011
............0111`],
  [cbgsprig_a, bitmap`
777777777700000.
7777777770444440
7777777704444044
7777777044440444
7777770444004444
7777770440444440
7777770404444007
7777770044000777
7777770440777777
7777770007770000
7777777777002222
7777777700222222
7777777702000222
7777777020222022
7777777022222222
7777770000000000`],
  [cbgsprig_b, bitmap`
7777777777777777
0077777777777777
0000077777777777
0070007777777777
0770077777777777
7700777777777777
7700777777777777
7700777777777777
7000777777777777
0000007777777777
2222220077777777
2222222207777777
2200022220777777
2022202220777777
2222222222077777
0000022222077777`],
  [cbgsprig_c, bitmap`
0020002222077777
0200002222077777
0000002222077777
2000222222077777
2222222222077777
2222222222077777
2222220022077777
2200002222077777
0022222222077777
2222222222077777
2222222222077777
2222222222077777
2222222222077777
2222222222077777
2222222220777777
2222222220777777`],
  [cbgsprig_d, bitmap`
7777770020002220
7777770200002220
7777770000022220
7777702222222222
7777702222222222
7777702222222222
7777702222222222
7777770222222222
7777777000222222
7777777777000000
7777777777777702
7777777777777702
7777777777777022
7777777777777022
7777777777770022
7777777777770222`],
)

// Game speed, Segemnt freq., Orange prob., Red prob., Sprig freq., Evil Sprig prob., Sprig speed, Pink prob., Gray prob.
const levels = [
[300, 0.3, 0.1,  0.05,   0.03,  0.0, 550, 0.025, 0.025],
[300, 0.3, 0.15,  0.075,   0.04,  0.0, 550, 0.25, 0.05],
[250, 0.3, 0.2,  0.1,   0.05,  0.1, 500, 0.05, 0.05],
[200, 0.2, 0.25, 0.15,  0.06,  0.15, 450, 0.1,  0.1 ],
[200, 0.2, 0.25, 0.15,  0.07,  0.2, 400, 0.1,  0.1 ],
[100, 0.1, 0.4,  0.2,   0.1,  0.3, 300, 0.1,  0.1 ],
  ]

var music_p = playTune(music, Infinity)
var wallpaper = 0
const bg_colors = [green,black,sky,yellow,green]
const desktop = [map`
........................
........................
........................
........................
........................
...............r........
........................
........................
........................
........................
........................
........................
........................
.......accccccccb.......
........................
........................
qqqqqqqqqqqqqqqqqqqqqqqq
pppppppppppppppppppppppU
pppppppppppppppppppppppp`,map`
EEEEEEEEEEEEEEEEEEEEEEEE
........................
........................
EEEEEEEEEEEEEEEEEEEEEEEE
........................
...............r........
EEEEEEEEEEEEEEEEEEEEEEEE
........................
........................
EEEEEEEEEEEEEEEEEEEEEEEE
........................
........................
EEEEEEEEEEEEEEEEEEEEEEEE
.......accccccccb.......
........................
EEEEEEEEEEEEEEEEEEEEEEEE
qqqqqqqqqqqqqqqqqqqqqqqq
pppppppppppppppppppppppU
pppppppppppppppppppppppp`,map`
........................
..F..F................F.
........................
...........F......F.....
........................
...............r........
..F...F.................
............F...........
........................
...............F........
.........F...........F..
...................F....
........................
...F...accccccccb.......
........................
..................F.....
qqqqqqqqqqqqqqqqqqqqqqqq
pppppppppppppppppppppppU
pppppppppppppppppppppppp`,map`
K.......LK.......LK.....
........................
..IJ.......IJ.......IJ..
..LK.......LK.......LK..
........................
.....IJ.......IJr......I
.....LK.......LK.......L
........................
J.......IJ.......IJ.....
K.......LK.......LK.....
........................
..IJ.......IJ.......IJ..
..LK.......LK.......LK..
.......accccccccb.......
.....IJ.......IJ.......I
.....LK.......LK.......L
qqqqqqqqqqqqqqqqqqqqqqqq
pppppppppppppppppppppppU
pppppppppppppppppppppppp`,map`
........................
........................
........................
........................
....EEEEEEEEEEEEEEEE....
....EEEEEEEEEEEEEEEE....
....MNEEEEEEEEEEEEEE....
....POEEEEEEEEEEEEEE....
........................
............r...........
........................
........................
........................
.......accccccccb.......
........................
........................
qqqqqqqqqqqqqqqqqqqqqqqq
pppppppppppppppppppppppU
pppppppppppppppppppppppp`]
const gameover = map`
........................
........................
......pppppppppppp......
......pppppppppppp......
........................
........................
........................
........................
........................
........................
........................
........................
........................
........................
........................
........................
........................
........................
........................`
var progress = 0
var level
var points = 0
var lifes = 2
var game_speed 
var segment_freq
var orange_prob
var red_prob
var pink_prob
var gray_prob
var sprig_speed
var sprig_freq
var red_sprig_prob
var bonus_sprig_prob = 0.01
var interval
var sprig_interval
var can_replay = false
var evil_touch_count
var game_over = false

set_level(1)

setSolids([cursor])

onInput("s", () => {
  if (game_over) return
  let l = getFirst(lbar)
  if (l.y+4 == height()) return
  let col = getAll(sprig_a).concat(getAll(esprig_a)).concat(getAll(bsprig_a)).find((h) => h.x <= l.x+9 && h.x >= l.x-1 && l.y + 1 == h.y)
  if (col && col.type == esprig_a) bsod()
  if (col) {playTune(touch_snd);return}
  var bar_sprites = getAll(lbar).concat(getAll(rbar).concat(getAll(bar).concat(getAll(bbe).concat(getAll(beb).concat(getAll(boe).concat(getAll(beo)))))))
  for (let x = 0;x<bar_sprites.length;x++) {
    bar_sprites[x].y += 1
  } 
})

onInput("w", () => {
  if (game_over) return
  let l = getFirst(lbar)
  let col = getAll(sprig_a).concat(getAll(esprig_a)).concat(getAll(bsprig_a)).find((h) => h.x <= l.x+9 && h.x >= l.x-1 && l.y - 2 == h.y)
  if (col && col.type == esprig_a) bsod()
  if (col) {playTune(touch_snd);return}
  var bar_sprites = getAll(lbar).concat(getAll(rbar).concat(getAll(bar).concat(getAll(bbe).concat(getAll(beb).concat(getAll(boe).concat(getAll(beo)))))))
  for (let x = 0;x<bar_sprites.length;x++) {
    bar_sprites[x].y -= 1
  } 
})

onInput("d", () => {
  if (game_over) return
  let l = getFirst(rbar)
  if (l.x+1 == width()) return
  let col = getAll(sprig_a).concat(getAll(esprig_a)).concat(getAll(bsprig_a)).find((h) => h.x == l.x+1 && (l.y == h.y || l.y-1 == h.y))
  if (col && col.type == esprig_a) bsod()
  if (col) {playTune(touch_snd);return}
  var bar_sprites = getAll(lbar).concat(getAll(rbar).concat(getAll(bar).concat(getAll(bbe).concat(getAll(beb).concat(getAll(boe).concat(getAll(beo)))))))
  for (let x = 0;x<bar_sprites.length;x++) {
    bar_sprites[x].x += 1
  } 
})

onInput("a", () => {
  if (game_over) return
  let l = getFirst(lbar)
  if (l.x == 0) return
  let col = getAll(sprig_a).concat(getAll(esprig_a)).concat(getAll(bsprig_a)).find((h) => h.x == l.x-2 && (l.y == h.y || l.y-1 == h.y))
  if (col && col.type == esprig_a) bsod()
  if (col) {playTune(touch_snd);return}
  var bar_sprites = getAll(lbar).concat(getAll(rbar).concat(getAll(bar).concat(getAll(bbe).concat(getAll(beb).concat(getAll(boe).concat(getAll(beo)))))))
  for (let x = 0;x<bar_sprites.length;x++) {
    bar_sprites[x].x -= 1
  } 
})

onInput("i", () => {
  if (game_over) return
  let c = getFirst(cursor)
  c.y -= 1
  let sprig = getAll(sprig_a).concat(getAll(esprig_a)).concat(getAll(bsprig_a)).find((h) => (c.x == h.x || c.x-1 == h.x) && (c.y == h.y || c.y-1 == h.y))
  if (sprig) {get_sprig(sprig).forEach((x) => x.remove());points+=1;update_text();playTune(break_snd)}
})

onInput("k", () => {
  if (game_over) return
  let c = getFirst(cursor)
  c.y += 1
  let sprig = getAll(sprig_a).concat(getAll(esprig_a)).concat(getAll(bsprig_a)).find((h) => (c.x == h.x || c.x-1 == h.x) && (c.y == h.y || c.y-1 == h.y))
  if (sprig) {get_sprig(sprig).forEach((x) => x.remove());points+=1;update_text();playTune(break_snd)}
})

onInput("j", () => {
  if (game_over) return
  let c = getFirst(cursor)
  c.x -= 1
  let sprig = getAll(sprig_a).concat(getAll(esprig_a)).concat(getAll(bsprig_a)).find((h) => (c.x == h.x || c.x-1 == h.x) && (c.y == h.y || c.y-1 == h.y))
  if (sprig) {get_sprig(sprig).forEach((x) => x.remove());points+=1;update_text();playTune(break_snd)}
})

onInput("l", () => {
  if (game_over) return
  let c = getFirst(cursor)
  c.x += 1
  let sprig = getAll(sprig_a).concat(getAll(esprig_a)).concat(getAll(bsprig_a)).find((h) => (c.x == h.x || c.x-1 == h.x) && (c.y == h.y || c.y-1 == h.y))
  if (sprig) {get_sprig(sprig).forEach((x) => x.remove());points+=1;update_text();playTune(break_snd)}
})

afterInput(() => {
  check_segments(false)
 if (can_replay) {
   music_p = playTune(music, Infinity)
   if (lifes > 0) {set_level(level);return}
   lifes = 2
   set_level(1)
 }
})


function get_sprig(sprig) {
  return [
  getTile(sprig.x+1, sprig.y).find((x) => x.type == sprig_b || x.type == esprig_b || x.type == bsprig_b),
  getTile(sprig.x, sprig.y+1).find((x) => x.type == sprig_d || x.type == esprig_d || x.type == bsprig_d),
  getTile(sprig.x+1, sprig.y+1).find((x) => x.type == sprig_c || x.type == esprig_c || x.type == bsprig_c),
  sprig]
}
    
function set_level(_level) {
  evil_touch_count = -1
   level = _level
   game_over=false
  progress=0
  wallpaper = Math.max(wallpaper, Math.min(Math.floor((level-1)/3),4))
  _level = level == 16 ? 5 : Math.min(Math.floor((level-1)/3),4)
  game_speed = levels[_level][0]
 segment_freq = levels[_level][1]
 orange_prob = levels[_level][2]
 red_prob = levels[_level][3]
 sprig_freq = levels[_level][4]
 red_sprig_prob = levels[_level][5]
 sprig_speed = levels[_level][6]
 pink_prob= levels[_level][7]
 gray_prob = levels[_level][8]
  clearInterval(interval)
  interval = setInterval(update_segments, game_speed)
  clearInterval(sprig_interval)
  sprig_interval = setInterval(update_sprigs, sprig_speed)
  can_replay = false
  setMap(desktop[wallpaper])
    setBackground(bg_colors[wallpaper])
  update_text()
  if (lifes > 1) addSprite(width()-2,height()-2, heart)
  if (lifes > 2) addSprite(width()-3,height()-2, heart)
}

function check_segments(hhhh) {
  try {var bar_pos = tilesWith(lbar)[0][0]} catch(err){return}
  getAll(be).concat(getAll(eb).concat(getAll(oe).concat(getAll(eo).concat(getAll(re).concat(getAll(er)))))).concat(getAll(ge).concat(getAll(eg))).concat(getAll(pe).concat(getAll(ep))).forEach((x) => {
    if (x.y == height()-1) x.remove()
    if (hhhh) x.y += 1
    if ((x.y == bar_pos.y) && bar_pos.x <= x.x && x.x <= bar_pos.x+9) {
      x.remove()
      if (x.type == re || x.type == er) {
        bsod()
      } else {
        if (bar_pos.x + Math.floor(progress/10) <= x.x) {
          playTune(get_snd)
          if (x.type == ge || x.type == eg) return
          if (x.type == pe || x.type == ep) {
            if (progress == 0) return
            progress -= 5
            getTile(bar_pos.x + Math.floor(progress/10),bar_pos.y).forEach((the) => {
                // console.log(the.type)
              if (progress % 10){
                if (the.type == beb || the.type == beo) the.remove()
              } else {
                if (the.type == bbe || the.type == boe) the.remove()
              }
            })
            update_text()
            return
          }
          let to_add
          if (x.type == be || x.type == eb){
            if (progress%10) {
              to_add = beb
            } else {
              to_add = bbe
            }
          } else {
            if (progress%10) {
              to_add = beo
            } else {
              to_add = boe
            }
          }
          addSprite(bar_pos.x + Math.floor(progress/10), bar_pos.y, to_add)
          progress += 5
          update_text()
          if (progress == 100) {
            playTune(levelup_snd)
            let o = points
            points += 5 * getAll(bbe).concat(getAll(beb)).length
            if (points-o == 100) lifes = Math.min(3, lifes+1)
            if (o == points) points += 100.1
            set_level(level+1)
          }
        } else {playTune(break_snd)}
      }
    }
  })
}

function update_text() {
    clearText()
  addText(points+" points\nLevel "+level, {x:0,y:14,color:color`0`})
  addText(progress+"%", {x:progress > 5 ?17:18,y:15,color:color`0`})
  if (wallpaper == 4) addText("Sprigressbar\n Professional", {x:4, y:4, color:color`2`})
}

function bsod() {
  playTune(error_snd)
  setMap(gameover)
  setBackground(blue)
  music_p.end()
  game_over = true
  clearInterval(interval)
  clearInterval(sprig_interval)
  clearText()
  setTimeout(() => {can_replay = true},2000)
  addText("     GAME OVER!", {x:0,y:2,color:color`5`})
  lifes -= 1
  if (lifes == 0) addText("   Your game have\n    encountered\n     a problem\n\n   SkillError at\n      line YOU\n\n  Back to level 1\n   Press any key\n\n"+points+" points\nLevel "+level, {x:0,y:4,color:color`1`})
  else addText("   Your game have\n    encountered\n     a problem\n\n   SkillError at\n      line YOU\n\n     -1 heart\n   Press any key\n\n"+points+" points\nLevel "+level, {x:0,y:4,color:color`1`})
  
}

function update_segments() {
  check_segments(true)
  if (!game_over && Math.random() < segment_freq) {
    let to_add = [be, eb]
    let r = Math.random()
    if (r < red_prob) to_add = [re, er]
    else if (r < orange_prob + red_prob) to_add = [oe, eo]
    else if (r < orange_prob + red_prob + pink_prob) to_add = [pe, ep]
    else if (r < orange_prob + red_prob + pink_prob + gray_prob) to_add = [ge, eg]
    if (Math.random() < 0.5) to_add = to_add[0]
    else to_add = to_add[1]
    addSprite(Math.floor(Math.random()*24) ,0, to_add)
  }
}
function update_sprigs() {
  evil_touch_count -= 1
  if (evil_touch_count< -1) evil_touch_count = -1
  let l = getFirst(lbar)
  getAll(sprig_a).concat(getAll(esprig_a)).concat(getAll(bsprig_a)).forEach((h) => {
    if(game_over) return
      let direction = []
      if (h.x < l.x+4) direction.push('right')
      if (h.x > l.x+4) direction.push('left')
      if (h.y < l.y) direction.push('down')
      if (h.y > l.y) direction.push('up')
      switch (direction[Math.floor(Math.random()*direction.length)]) {
        case "left":
          if (h.x-1 == l.x+9 && (l.y == h.y || l.y == h.y+1)) {
            if (h.type==bsprig_a) {
              points+= 50
              playTune(bonus_snd)
              update_text()
              get_sprig(h).forEach((x) => x.remove())
            }  else if (h.type == esprig_a) {playTune(touch_snd);evil_touch_count+=2;if(evil_touch_count==3){bsod();return};break}
            break
          }
          get_sprig(h).forEach((the) => {the.x-=1})
          break
        case "right":
          if (h.x+2 == l.x && (l.y == h.y || l.y == h.y+1)) {
            if (h.type==bsprig_a) {
              points+= 50
              playTune(bonus_snd)
              update_text()
              get_sprig(h).forEach((x) => x.remove())
            } else if (h.type == esprig_a) {playTune(touch_snd);evil_touch_count+=2;if(evil_touch_count>=3){bsod();return};break}
            break
          }
          get_sprig(h).forEach((the) => {the.x+=1})
          break
        case "up":
          if (h.x <= l.x+9 && h.x >= l.x-1 && l.y + 1 == h.y) {
            if (h.type==bsprig_a) {
              points+= 50
              playTune(bonus_snd)
              update_text()
              get_sprig(h).forEach((x) => x.remove())
            } else if (h.type == esprig_a) {playTune(touch_snd);evil_touch_count+=2;if(evil_touch_count==3){bsod();return};break}
            break 
          }
          get_sprig(h).forEach((the) => {the.y-=1})
          break
        case "down":
          if (h.x <= l.x+9 && h.x >= l.x-1 && l.y - 2 == h.y) {
            if (h.type==bsprig_a) {
              points+= 50
              playTune(bonus_snd)
              update_text()
              get_sprig(h).forEach((x) => x.remove())
            } else if (h.type == esprig_a) {playTune(touch_snd);evil_touch_count+=2;if(evil_touch_count==3){bsod();return};break}
            break
          }
          get_sprig(h).forEach((the) => {the.y+=1})
          break
      }
  })
  if (!game_over && Math.random() < sprig_freq) {
    let to_add = [sprig_a, sprig_b, sprig_c, sprig_d]
    let r = Math.random()
    if (r < red_sprig_prob) to_add = [esprig_a, esprig_b, esprig_c, esprig_d]
    else if (r < red_sprig_prob+bonus_sprig_prob) to_add = [bsprig_a, bsprig_b, bsprig_c, bsprig_d]
    do {
      var x = Math.floor(Math.random()*(width()-1))
      var y = Math.floor(Math.random()*(height()-3))
    } while ((y == l.y || y+1 == l.y) && x >= l.x && x <= l.x + 10)
    addSprite(x, y, to_add[0])
    addSprite(x+1, y, to_add[1])
    addSprite(x, y+1, to_add[3])
    addSprite(x+1, y+1, to_add[2])
  }
}
